class TransactionManager {  
    private transactionActive = false;  
    
    public startTransaction() {  
      // 逻辑来开始一个新的事务，比如连接数据库等  
      this.transactionActive = true;  
    }  
    
    public commitTransaction() {  
      // 逻辑来提交当前的事务  
      this.transactionActive = false;  
    }  
    
    public rollbackTransaction() {  
      // 逻辑来回滚当前的事务  
      this.transactionActive = false;  
    }  
    
    public executeInTransaction<T>(operation: () => T): T {  
      try {  
        this.startTransaction();  
        const result = operation();  
        this.commitTransaction();  
        return result;  
      } catch (error) {  
        this.rollbackTransaction();  
        throw error;  
      }  
    }  
  }